<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Pinyin 2 Hanzi</title>
</head>
	<body style='font-family: Georgia, "Times New Roman", "KaiTi", "楷体", STKaiti, "华文楷体", serif'>
		<table style="margin-left: auto; margin-right: auto; text-align: center"><tr><td><span id="question">jīn<b>nián</b> 2013 <b>nián</b></span></td></tr>
		<tr><td><table width="100%"><tr><td style="background-color: green" onClick="correctClicked();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style="background-color: red" onClick="incorrectClicked();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></td></tr>
	<tr><td><span id="answer1" onClick="toggleShowAnswer1();" style="font-size: 300%">?</span></td></tr>	
	<tr><td><span id="answer2" onClick="toggleShowAnswer2();">?</span></td></tr>	
	<tr><td><span id="answer3" onClick="toggleShowAnswer3();">?</span></td></tr>	
	</table>
<div style="display: none" id="questions">
#2013-10-07
jīn[nián] jǐ[nián]?;年;216;year
jīntiān jǐ[yuè]?;月;506;month
jīntiān [xīngqī]jǐ?;星期;219+220;week
chàngkē hěn [wánr];玩儿;317+92;fun
nǐ jǐyuè jǐhào [chū]shēng?;出;226;to be born
nǐ jǐyuè jǐhào [guò] shēngrì?;过;430;celebrate
wǒ èrshí [suì];岁;217;years of age
#2013-10-14
蛋糕 dàngāo 235+236 cake
送 sòng 288 give as gift
礼物 lĭwù 333+173 present
光盘 guāngpán 264+265 compact disc
唱歌 chànggē 328+329 sing
祝你生日快乐 zhùnĭshēngrìkuaìlè 230+245
跳舞 tiàowŭ 330+331 dance
花儿 huār - flower
前 qián 493 the one before last
后 hòu 494 the one after next
#2013-10-21
点 diǎn 304 o'clock
分 fēn 287 minute
刻 kè 309 quarter
半 bàn 318 half
差 chà 308 to fall short of
早上 zǎoshang - early morning
中午 zhōngwǔ 222 noon
数学 shùxué 172 mathematics 
属 shǔ 227 to be born in the year of (one of the 12 animals)
</div>
<script>
questionsLines = document.getElementById("questions").textContent.split("\n")
questions = []
for (i in questionsLines) {
  var line = questionsLines[i].trim()
  if (line[0] != "#" && line != "") {
    questions.push(questionsLines[i])
  }
}
startRound()
pickQuestion()

	function startRound() {
		todo = questions.slice(0)
	}

	function pickQuestion() {
questionIndex = Math.floor(Math.random() * todo.length)
qanda = todo[questionIndex]
qanda_semi = qanda.indexOf(";")
if (qanda_semi >= 0) {
	qanda_fields = qanda.split(";")
	q = qanda_fields[0].replace("[", "<b>").replace("]", "</b>")
	a1 = qanda_fields[1]
	a2 = qanda_fields[2]
	a3 = qanda_fields[3]
} else {
	qanda_space = qanda.indexOf(" ")
	a1 = qanda.substring(0, qanda_space)
	a = qanda.substring(qanda_space + 1)
	a_space1 = a.indexOf(" ")
	a_space2 = a.indexOf(" ", a_space1 + 1)
	q = a.substring(0, a_space1);
	a2 = a.substring(a_space1 + 1, a_space2);
	a3 = a.substring(a_space2 + 1);
}

document.getElementById("question").innerHTML = q
resetView()
updateView()
	}

function resetView() {
	showAnswer1 = showAnswer2 = showAnswer3 = false;
}
	
function updateView() {
	document.getElementById("answer1").textContent = showAnswer1 ? a1 : "?"
	document.getElementById("answer2").textContent = showAnswer2 ? a2 : "?"
	document.getElementById("answer3").textContent = showAnswer3 ? a3 : "?"
}

function toggleShowAnswer1() {
	showAnswer1 = !showAnswer1;
	updateView();
}

function toggleShowAnswer2() {
	showAnswer2 = !showAnswer2;
	updateView();
}

function toggleShowAnswer3() {
	showAnswer3 = !showAnswer3;
	updateView();
}

	function correctClicked() {
		todo.splice(questionIndex, 1);
		if (todo.length == 0) {
			window.alert("Round complete! Starting next round...")
			startRound()
		}
		pickQuestion()
	}
	
	function incorrectClicked() {
		pickQuestion()
	}

</script>
</body>
</html>